
extends Node2D

var explode
var velocity=Vector2(0,10)
var life=5
var score=1
var root
func _ready():
	explode=get_node("Sprite/explode")
	set_pos(Vector2(randf()*get_viewport_rect().size.width,-100))
	set_process(true)
	root=get_tree().get_current_scene()
	pass

func _process(delta):
	var pos=get_pos()
	pos+=velocity
	set_pos(pos)
	if pos.y>get_viewport_rect().size.height+100:
		queue_free()


func _on_enemy_area_area_enter_shape( area_id, area, area_shape, area_shape ):
	if area.get_name()!="enemy_area":
		get_node("Sprite/explode").play("attacked",-1,5)
		life-=1
		if life==0:
			if area.get_name()=="bullet_area":
				root.score+=score
			velocity*=.6
			root.get_node("score").set_text(str(root.score))
			get_node("enemy_area").queue_free()
			explode.play("explode")
			get_node("sound").play("crash")
func _on_explode_finished():
	if life<=0:
		queue_free()

